<?php
include_once APPLICATION_DIR.'/application/model/dao/interfaces/PrepareStmtFactory.class.php';

class ORMBuilder implements IORMBuilder {
    
    private $data_stored;
    private $prepare_stmt;
    
    public function __construct($dbms){
        $this->data_stored = array();
        $this->prepare_stmt =  PrepareStmtFactory::createInstance($dbms);
    }
    
    public function buildCountry(RTO $rto){
        if(!isset($this->data_stored[$rto->getName()])){
            $this->data_stored[$rto->getName()] = $this->prepare_stmt->createCountry();
        }
        $rto->country_stmt = $this->data_stored[$rto->getName()];
    }
    
    public function buildCity(RTO $rto){
        if(!isset($this->data_stored[$rto->getName()])){
            $this->data_stored[$rto->getName()] = $this->prepare_stmt->createCity();
        }
        $rto->city_stmt = $this->data_stored[$rto->getName()];
    }
    
    public function buildPointSale(RTO $rto){
        if(!isset($this->data_stored[$rto->getName()])){
            $this->data_stored[$rto->getName()] = $this->prepare_stmt->createPointSale();
        }
        $rto->point_sale_stmt = $this->data_stored[$rto->getName()];
    }
    
    public function buildGroupCategory(RTO $rto){
        if(!isset($this->data_stored[$rto->getName()])){
            $this->data_stored[$rto->getName()] = $this->prepare_stmt->createGroupCategory();
        }
        $rto->group_category_stmt = $this->data_stored[$rto->getName()];
    }
    
    public function buildGroupCategories(RTO $rto){
        if(!isset($this->data_stored[$rto->getName()])){
            $this->data_stored[$rto->getName()] = $this->prepare_stmt->createGroupCategories();
        }
        $rto->group_categories_stmt = $this->data_stored[$rto->getName()];
    }
}

